﻿using AioiSystems.DotModule;
using AioiSystems.DotModule.Barcode;
using ControllerManageServer.ActionModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerManageServer.LabelDevice.Aioi
{
    class MWU2402LabelDevice: BaseLabelDevice
    {
        /// <summary>
        /// 字体
        /// </summary>
        public string FontName = "宋体";
        /// <summary>
        /// 字体大小
        /// </summary>
        public int FontSize = 13;
        /// <summary>
        /// 行高
        /// </summary>
        public int LineHeight = 96;
        /// <summary>
        /// X轴位置
        /// </summary>
        public int PositionX = 50;
        /// <summary>
        /// Y轴位置
        /// </summary>
        public int PositionY = 0;

        public MWU2402LabelDevice() {
            SeqLength = 50;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="iModel"></param>
        /// <param name="iSeq"></param>
        /// <param name="iFnSeq"></param>
        /// <returns></returns>
        public override byte[] Action(ActionModelAbstract iModel, string iSeq, string iFnSeq = null)
        {
            DisplayPainter displayPainter = new DisplayPainter(DisplayPainter.DisplaySizeType.Size200x96, true);
            displayPainter.ClearDisplay();
            displayPainter.PutBarcode(new QRCode
            {
                Font = new System.Drawing.Font(FontName, FontSize),
                Height = LineHeight,
                BarcodeDataVisibled = true,
                BarcodeData = iSeq
            }, PositionX, PositionY);
            // 二维码的字节流
            byte[] codeStream = displayPainter.GetLocalDisplayImage().GetImage();

            string cmd = $"XA{Address}10000002000960";

            List<byte> result = new List<byte>();
            result.AddRange(DefaultEncoding.GetBytes(cmd));
            result.AddRange(codeStream);
            return result.ToArray();
        }
    }
}
